<?php
namespace app\wxapp\controller;

use app\wxapp\controller\Base;
use app\common\model\Purchase as PurchaseModel;
use app\common\model\Styles as StylesModel;
use app\common\model\Brands as BrandsModel;

class Purchase extends Base{

    /**
     * 最新的自营活动
     */
    public function activity(){
        $purchase = PurchaseModel::where([])->order('add_time desc')->find();
        //查找风格

        $model['related'] = json_decode($purchase['related'],true);
        $styles = [];
        $brands = [];
        foreach($model['related'] as $key => $val ){
            array_push($styles,$key);
            if(!empty($val)){
                foreach($val as $kk => $vv ){
                    array_push($brands,$kk);
                }
            }
        }

        $styles = StylesModel::where('oid','in',$styles)->column('oid,name,introduce','oid');
        $brands = BrandsModel::where('oid','in',$brands)->column('oid,name','oid');

        foreach($styles as $key => $val ){
            $styles[$key]['introduce'] = mb_substr($val['introduce'],0,15,'UTF-8').'...';
        }

        $purchase['styles'] = $styles;
        $purchase['brands'] = $brands;

        $this->success("获取成功",'',$purchase);
    }


}
